package top.drinyeit.nongmao.dialog;

import android.app.Activity;
import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.view.Display;
import android.view.Gravity;
import android.view.Window;
import android.view.WindowManager;

import top.drinyeit.nongmao.R;

/**
 * Created by bigHead on 2017/11/15.
 */

public class AddCartDialog extends Dialog {

    private Context context;      // 上下文
    private int layoutResID;      // 布局文件id
    private int[] listenedItems;  // 要监听的控件id

    public AddCartDialog(Context context, int layoutResId) {
        super(context, R.style.dialog_bottom_custom); //dialog的样式
        this.context = context;
        this.layoutResID = layoutResId;
        this.listenedItems = listenedItems;

    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        Window window = getWindow();
        window.setGravity(Gravity.BOTTOM); // 此处可以设置dialog显示的位置为底部
        window.setWindowAnimations(R.style.bottom_menu_animation); // 添加动画效果
        this.requestWindowFeature(Window.FEATURE_NO_TITLE);
        setContentView(layoutResID);

        WindowManager windowManager = ((Activity) context).getWindowManager();
        Display display = windowManager.getDefaultDisplay();
        WindowManager.LayoutParams lp = getWindow().getAttributes();
        lp.width = display.getWidth(); // 设置dialog宽度为屏幕
        getWindow().setAttributes(lp);
        setCanceledOnTouchOutside(true);// 点击Dialog外部消失

    }


}
